perm filename TSERVO.FAI[H,BGB] blob sn#119362 filedate 1974-11-30 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00007 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	ENTRY TSERVO, CALPOT, CALSTP,CALLEN, NXTLEN, CALSER
C00004 00003	COUNTERS
C00007 00004	OPDEF	DISMIS [CALLI 400024]
C00010 00005		LSH 7,1
C00013 00006		MOVE 11,LENS		MIGHT BE CHANGED BY PDP10
C00017 00007	SERVO CONTROL ROUTINES
C00020 ENDMK
C⊗;
ENTRY TSERVO, CALPOT, CALSTP,CALLEN, NXTLEN, CALSER

	TITLE TSERVO ROUTINE

INTERNAL STATUS, P1, P2, P3, L1, L2, L3, E1, E2, E3,LENS,CREF

STAT←17		;STATUS AC
RELAY←16	;NEW RELAY BITS AC
OREL←15		;OLD RELAY BITS AC

;REGISTERS AVAILABLE TO USER

STATUS:	0;	STATUS BITS
LENS:	0;	LENS NUMBER (-1 TO CHANGE TO NEXT LENS)
	 	;		*** WARNING ORDER FIXED TO ↓↓↓↓↓ ***
P1:	0;	LATEST POT READINGS - FOCUS 
P2:	0;	TILT (add divided by reference voltage)
P3:	0;	PAN
CREF:	0;	REFERENCE VOLTAGE
L1:	0;	FINAL POT VALUES
L2:	0
L3:	0
E1:	4.0;	TOLERENCES
E2:	10.0
E3:	10.0

;REGISTERS FOR INTERNAL USE ONLY

;RELAY BITS FOR INCREASING POT READINGS

UP:	20000;	FOCUS FAR
	200000;	TILT DOWN
	100000;	PAN CCW

;RELAY BITS FOR DECREASING POT READINGS

DOWN:	10000;	FOCUS NEAR
	400000;	TILT UP
	40000;	PAN CW

;RELAY TEST BITS

TEST:	30000;	FOCUS
	600000;	TILT
	140000;	PAN

;PREVIOUS POT READINGS

X1:	0
X2:	0
X3:	0
;COUNTERS

LCTR:	0;	LENS COUNT
FCTR:	0;	FOCUS COUNT
TCTR:	0;	TILT COUNT
PCTR:	0;	PAN COUNT
GCTR:	0;	GENERAL COUNT
DCTR:	0;	LENS DELAY COUNT
LBITS:	0;	LAST RELAY BITS
LLENS:	0;	LAST LENS NUMBER SEEN  *** WARNING ORDER FIXED TO ↑↑↑↑ ***

;COUNTER MAXIMUMS;

.DEL:	200;	COUNTER FOR HUNG A-D
.MISSD:	25;	DATA MISSED COUNT
.CNTR:	=120;	SERVO STOP COUNTER MAX -FOCUS
	=40;	   " -	TILT
	=40;	   " -	PAN
.WCNTR:	=100;	LENS DELAY COUNTER
.LCNTR:	=240;	LENS STOP MAX
.GCNTR:	=2200;	GENERAL COUNTER MAX

;BITS IN STATUS WORD

.DONE←←1	;ALL ACTIONS COMPLETED (OR ERROR OCCURED)
.RUN←←2		;TSERVO RUNNING
.READ←←4	;POT READ REQUEST
.SERVO←←10	;POT SERVO REQUEST
.LENS←←20	;LENS CHANGE REQUEST
.LREAD←←40	;LENS READ REQUEST
.MISS←←100	;DATA MISSED ERROR
.ADH←←200	;AD HUNG ERROR
.LHANG←←400	;LENS TIMED OUT ERROR
.FHANG←←1000	;FOCUS   "
.THANG←←2000	;TILT	 "
.PHANG←←4000	;PAN     "
.GHANG←←10000	;GENERAL "
.CONFL←←100000	;CONFLICT FLAG
.NCONF←←200000	;CONFLICT THIS TICK - INTERNAL FLAG ONLY
.LRUN←←400000	;LENS RUN BIT -         "      "     "

SHANG:	.FHANG
	.THANG
	.PHANG

.XLENS←←4000	;LENS RELAY BIT
.AD←←424	;AD DEVICE NUMBER
.DATA←←204	;136 DEVICE NUMBER
.MISC←←700	;KLUDGE BAY DEVICE NUMBER
.TUR←←600	;LENS INPUT DEVICE NUMBER
.REL←←40	;RELAY REGISTER SELECT
OPDEF	DISMIS [CALLI 400024]
OPDEF	SPCWAR [43B8]

TSERVO:	MOVE STAT,STATUS	;START OF SPACEWAR CODE - LOAD REGISTERS
	MOVE OREL,LBITS
	SETZM RELAY		;CLEAR NEW RELAY BITS
	MOVEM 3,SAVE3#		;SAVE TICK COUNTER
	ORI STAT,.RUN		;SET RUN BIT
	TRNE STAT,.DONE
	JRST COUT		;DONE BIT SET - IDLE UNTIL STOPPED
	TRZ STAT,.MISS!.ADH!.GHANG!.LHANG!.PHANG!.THANG!.FHANG!.NCONF
				;CLEAR ERROR BITS
	AOS 1,GCTR		;INDEX GENERAL COUNT
	CAMLE 1,.GCNTR
	JRST [	ORI STAT,.GHANG	;SPW GENERAL TIME OUT ERROR
		JRST DOUT]
	TRNN STAT,.READ!.SERVO
	JRST NOPOT		;NO POT READING OR SERVOING REQUESTED
.FOO.:	CONI .DATA,4		;CHECK FOR CONFLICTS
	ANDI 4,7
	JUMPN 4,[ORI STAT,.CONFL!.NCONF
		JRST NOPOT]
	MOVE 11,[IOWD 3,5]	;IOWD TO STORE READINGS
	MOVE 4,.MISSD		;SET DATA MISSED COUNT
TURNON:	CONO .DATA,4250		;TURN ON 136
	CONO .AD,172030		;TURN ON A-D
.L1:	MOVE 3,.DEL		;SET DEVICE HUNG COUNT
	CONSO .DATA,1000	;WAIT FOR 136 DONE
	SOJGE 3,.-1		;AND COUNT DOWN
	JUMPL 3,[ORI STAT,.ADH	;HUNG AD, SET ERROR BIT
		CONO .AD,4000	;AND TURN OFF
		JRST DOUT]
	CONSZ .DATA,10000	;TEST FOR DATA MISSED
	JRST [	CONO .AD,4000
		SOJG 4,[	;AND COUNT DOWN
			MOVEI 3,12
.L2:			SOJGE 3,.L2
			JRST TURNON]
		ORI STAT,.MISS	;LIMIT REACHED - SET ERROR BIT
		CONO .AD,4000	;MISSED - TURN OFF
		JRST DOUT]
	BLKI .DATA,11		;READ IN POTS
	SKIPA
	JRST .L1
	CONO .AD,4000		;STOP A-D
	ASH 7,-=24		;UNPACK REFERENCE
	MOVE 10,7
	FSC 10,233
	ASHC 5,-=24		;UNPACK AND STORE READINGS
	LSH 6,1
	ASHC 6,-=24
	LSH 7,1
	ASH 7,-=24
	FSC 5,233		;AFTER GETTING RATIO WITH REFERENCE
	FSC 6,233
	FSC 7,233
	FDVR 5,10
	FDVR 6,10
	FDVR 7,10
	MOVE 11,[XWD 5,P1]
	BLT 11,CREF
	TRNN STAT,.SERVO
	JRST NOPOT		;NO POT SERVO REQUESTED
	MOVEI 1,2		;LOOP THROUGH 3 POT READINGS
LOOP:	MOVE 2,P1(1)		;DIFFERENCE WITH FINAL READING
	FSBR 2,L1(1)
	TDNN OREL,TEST(1)	;TEST IF THIS MOTOR WAS ON
	JRST NOMOT
	MOVE 3,P1(1)		;YES - DIFFERENCE WITH LAST READING
	FSBR 3,X1(1)
	MOVMS 3
	FMPR 3,CREF		;AND GET ACTUAL READING
	FSBR 3,E1(1)		;AND TEST FOR NO MOVEMENT
	JUMPLE 3,.+4
	SETOM FCTR(1)		;CLEAR COUNTER IF MOVING
	MOVE 3,P1(1)		;AND UPDATE LAST READING
	MOVEM 3,X1(1)
	AOS 3,FCTR(1)		;ELSE INCREMENT
	CAMLE 3,.CNTR(1)	;AND TEST FOR MAX
	JRST [	OR STAT,SHANG(1)
		JRST DOUT]	;SET HUNG BITS FOR PROPER MOTOR
NOMOT:	MOVM 3,2		;TEST FOR NEAR FINAL READING
	FMPR 3,CREF
	SUB 3,E1(1)
	JUMPGE 3,[SKIPL 2	;NO - SET RELAY BITS
		OR RELAY,UP(1)
		SKIPGE 2
		OR RELAY,DOWN(1)
		JRST .+1]
	SOJGE 1,LOOP		;AND RETURN FOR NEXT READING
	TRNN RELAY,770000
	TRZ STAT,.SERVO		;CLEAR SERVO REQUEST BIT IF DONE
NOPOT:	TRNN STAT,.LENS!.LREAD
	JRST OUT		;NO LENS CHANGE OR READING REQUESTED
	CONI .TUR,10		;WHICH LENS IS UP
	LSH 10,-=13
	ANDI 10,3
	TRNN STAT,.LENS
	JRST [	MOVEM 10,LENS	;IF READ ONLY - STORE
		JRST OUT]	;AND EXIT
	MOVE 11,LENS		;MIGHT BE CHANGED BY PDP10
	SKIPGE 11
	MOVE 11,LENTAB(10)	;FIRST TIME THROUGH AND NEXT LENS WANTED
	ANDI 11,3		;MAKE SURE HONEST OR WE LOOP
	MOVEM 11,LENS
	CAMN 10,LENS		;REQUESTED LENS UP
	JRST [	AOS 12,DCTR	;YES - INCREMENT DELAY COUNT
		CAML 12,.WCNTR	;AND TEST FOR END OF WAIT
		TRZ STAT,.LENS!.LRUN;	YES - CLEAR LENS CHANGE BIT
		JRST OUT]
	CAMN 10,LLENS		;SAME LENS AS LAST TIME?
	JRST [	AOS 1,LCTR	;YES - INDEX COUNT
		CAMGE 1,.LCNTR	;AND CHECK FOR MAX
		JRST .+3
		ORI STAT,.LHANG	;SET LENS HUNG BIT
		JRST DOUT]
	MOVEM 10,LLENS		;LENS CHANGED - UPDATE
	SETZM LCTR		;AND CLEAR COUNT
	ORI RELAY,.XLENS	;SET RELAY BIT FOR LENS MOTOR
	ORI STAT,.LRUN		;AND STATUS BIT
OUT:	TRNN RELAY,.XLENS!770000	;TEST FOR ANY RELAY BITS ON
	JRST [	TRNE STAT,.NCONF!.LRUN	;OR CONFLICT BIT SET FOR THIS TICK
		JRST .+1
		JRST DOUT]	;NONE - WE ARE FINISHED
	SKIPL SAVE3		;CHECK TICK COUNT
	JRST AOUT		;EXIT NORMALLY
	JRST BOUT		;TURN OFF MOTOR - WE ARE GOING TO BE SHUFFLED

;EXITS FROM SERVO ROUTINE

DOUT:	ORI STAT,.DONE		;DONE EXIT - OK OR ERROR
	TRZ STAT,.LRUN		;CLEAR INTERNAL BITS
COUT:	SETZM LCTR		;EXIT WHEN IDLING
	MOVE 1,[XWD LCTR,LCTR+1];CLEAR COUNTERS, ETC.
	BLT 1,LLENS
BOUT:	SETZM RELAY		;SHUFFLE EXIT - TURN OFF ALL MOTORS
	SETZM FCTR
	SETZM PCTR
	SETZM TCTR
AOUT:	MOVEM RELAY,LBITS	;NORMAL EXIT - STORE RELAY BITS
	TRZ STAT,.NCONF		;CLEAR MORE INTERNAL BITS
	MOVEM STAT,STATUS	;STORE STATUS
	CONO .MISC,.REL(RELAY)	;SET RELAY REGISTER TO START MOTORS
	DISMIS

LENTAB:	OCT 1,3,2,0		;LENS NUMBER TABLE
;SERVO CONTROL ROUTINES

CALSER:	SKIPN CALFLG#		;READ POTS FIRST TIME
	SKIPA 1,[.READ]		;SERVO TO INITIAL POSITION THEREAFTER
	MOVEI 1,.SERVO
	MOVEM 1,STATUS
	PUSH 17,[.+2]
	JRST SPWRUN
	SKIPE CALFLG
	POPJ 17,
	MOVE 1,[XWD P1,L1]
	BLT 1,L3
	SETOM CALFLG
	POPJ 17,

NXTLEN:	MOVEI 1,.LENS		;GET NEXT LENS
	SETOM LENS
	JRST SPWRUN-1

CALPOT:	MOVEI 1,.READ		;READ POTS
	JRST SPWRUN-1

CALLEN:	SKIPA 1,[.LREAD]	;READ LENS
CALSTP:	MOVEI 1,.DONE		;STOP MOTORS
	MOVEM 1,STATUS
SPWRUN:	SPCWAR 0,636367
	SPCWAR 1,TSERVO
	MOVE 1,STATUS
	SETCM 1,1
	TRNE 1,.DONE!.RUN
	JRST .-3
	SPCWAR 0,636367
	POPJ 17,
	END